<template>
	<div id="friend-merchant-manage" class="w-h-100 pos-r flex-1 apply-container"
		style="box-sizing: border-box; overflow: hidden">
		<div class="w-h-100 ver-flex pos-a" style="box-sizing: border-box; padding: 6px"   >
			<div class="search-s page-public-s" style="box-sizing: border-box" v-if="!productUnitList"  >
				<el-card shadow="never" :body-style="{ paddingBottom: '0' }"  >
					<el-form class="box-f" ref="queryForm" :inline="true">
						<!-- <el-form-item label="友商名称：">
                            <el-input v-model="transferVal" placeholder="请输入搜索友商名称" />
                        </el-form-item> -->

						<el-form-item >
						<el-button v-if="$hasPer('enterpriseInformation1:add')" @click="nodeClick" icon="ele-Plus"
							type="primary"> 新增 </el-button>
						</el-form-item>
					</el-form>
				</el-card>
			</div>

			<div style="box-sizing: border-box" class="flex-1 pos-r">
				<div class="pos-a w-h-100" style="box-sizing: border-box">
					<el-card class="box-card w-h-100" shadow="never" style="margin-top: 16px">
						<div style="" class="w-h-100 ver-flex">
							<div class="flex-1 pos-r">
								<div class="pos-a w-h-100">
									<el-table ref="excelRef" :data="[productUnitList]" class="w-h-100"
										style="width: 100%" border element-loading-background="rgba(0, 0, 0, 0.5)">
										<el-table-column type="index" label="序号" width="55"
											:show-overflow-tooltip="true" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true" prop="v_Name"
											label="企业名称" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true" prop="v_Uniscid"
											label="统一社会信用代码" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_BusinessStatusName" label="营业状态" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true" label="组织机构代码"
											align="center">
											<template #default="scope">
												<span v-if="scope.row.v_OrganizationCode">{{
													scope.row.v_OrganizationCode }}</span>
												<span v-else> - </span>
											</template>
										</el-table-column>
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_AdminsrtativeDivision" label="所属行政区域编码" align="center" />
										<!-- <el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_EconTypeName" label="国民经济类型名称" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_EconCategory" label="国民经济行业分类" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_RegulatoryIndustry" label="监管行业" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_LegalRepresentative" label="法人代表人（经营者）" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_ContactNumber" label="联系电话" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_RegisAddrCode" label="注册地址行政区划" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_RegisAddr" label="注册地址" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_AddressOperatingCode" label="经营地址行政区划" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_AddressOperating" label="经营地址" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="f_LocationCoordinatesLongitude" label="所在地坐标-经度" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="f_LocationCoordinatesLatitude" label="所在地坐标-纬度" align="center" /> -->
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="isLocatedChemical" label="企业是否位于化工园区" align="center">
											<template #default="{ row }">
												{{ row.isLocatedChemical ? '是' : '否' }}
											</template>
										</el-table-column>
										<!-- <el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_ChemicalIndustryPark" label="化工园区名称" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true" prop="v_EntpSize"
											label="企业规模" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="degisterDate" label="成立日期" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true" prop="n_RegCap"
											label="注册资本（万元）" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true" prop="v_OpScope"
											label="主营业务" align="center" /> -->
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_MainInChargeName" label="主要负责人" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_SafetyProductionManagementName" label="安全生产管理负责人" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="v_SafeOrgName" label="安全生产管理机构" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="d_SafeOrgEstablishDate" label="安全生产管理机构设日期" align="center" />
										<!-- <el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="d_LastDSTime" label="最后一次数据同步时间" align="center" /> -->
										<!-- <el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="d_InitiateDSTime" label="发起同步时间" align="center" /> -->
										<!-- <el-table-column min-width="120" :show-overflow-tooltip="true" prop="isTobeDS"
											label="待同步至双控" align="center" /> -->

										<el-table-column min-width="120" :show-overflow-tooltip="true" label="产品描述"
											align="center">
											<template #default="scope">
												<span v-if="scope.row.product_Description">{{
													scope.row.product_Description }}</span>
												<span v-else> - </span>
											</template>
										</el-table-column>
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="createdTime" label="创建时间" align="center" />
										<el-table-column min-width="100" :show-overflow-tooltip="true"
											prop="createdUserName" label="创建人" align="center" />
										<el-table-column min-width="120" :show-overflow-tooltip="true"
											prop="updatedTime" label="更新时间" align="center">
											<template #default="scope">
												<span v-if="scope.row.updatedTime">{{ scope.row.updatedTime }}</span>
												<span v-else> - </span>
											</template>
										</el-table-column>
										<el-table-column min-width="100" :show-overflow-tooltip="true"
											prop="updatedUserName" label="更新人" align="center">
											<template #default="scope">
												<span v-if="scope.row.updatedUserName">{{ scope.row.updatedUserName
													}}</span>
												<span v-else> - </span>
											</template>
										</el-table-column>
										<el-table-column min-width="140" label="操作" align="center" fixed="right">
											<el-table-column min-width="240" fixed="right" align="center">
												<template #default="scope">
													<div class="operate-s">
														<el-button v-if="$hasPer('enterpriseInformation2:edit')"
															@click="nodeClick(scope.row)" class="icon-e" icon="ele-Edit"
															size="small" text type="primary"> 编辑</el-button>
														<el-button v-if="$hasPer('enterpriseQualification4:detail')"
															@click="editIdInfoHandler(scope.row)" class="icon-e"
															icon="ele-Edit" size="small" text type="success">
															详情</el-button>
														<el-button v-if="$hasPer('enterpriseInformation3:create')"
															size="small" @click="documentClick(scope.row)" text
															type="primary"> 附件管理 </el-button>
													</div>
												</template>
											</el-table-column>
										</el-table-column>
									</el-table>
								</div>
							</div>
							<!-- <div style="height: 30px; margin-top: 20px" class="hr-flex-start">
								<el-pagination v-model:currentPage="pageNo" v-model:page-size="pageSize"
									:total="totalRows" :page-sizes="[10, 20, 50, 100]" small background
									@size-change="handleSizeChange" @current-change="handleCurrentChange"
									layout="total, sizes, prev, pager, next, jumper" class="w-h-100" />
							</div> -->
						</div>
					</el-card>
				</div>
			</div>
		</div>
		<!-- 新增and编辑 -->
		<el-dialog draggable :close-on-click-modal="false" :close-on-press-escape="false" v-model="showDialogVisible"
			:title="editId ? '编辑' : '新增'" width="50%" @close="cancelUseClick">
			<el-form :model="ruleForm" label-position="top" label-width="120px" ref="formRef" :rules="rules">
				<el-divider content-position="left"> 基本信息 </el-divider>
				<el-row :gutter="35">
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="v_Name" label="企业名称">
							<el-input v-model="ruleForm.v_Name" placeholder="企业名称" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="v_Uniscid" label="统一社会信用代码">
							<el-input v-model="ruleForm.v_Uniscid" placeholder="统一社会信用代码" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="n_BusinessStatus" label="营业状态">
							<el-select v-model="ruleForm.n_BusinessStatus" placeholder="营业状态" clearable
								style="width: 100%">
								<el-option v-for="item in businessStatuLis" :key="item.value" :label="item.label"
									:value="item.value" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="组织机构代码">
							<el-input v-model="ruleForm.v_OrganizationCode" placeholder="组织机构代码" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="v_AdminsrtativeDivision" label="所属行政区域编码">
							<el-input v-model="ruleForm.v_AdminsrtativeDivision" placeholder="所属行政区域编码" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="国民经济类型">
							<el-select v-model="ruleForm.n_EconType" placeholder="国民经济类型" clearable style="width: 100%">
								<el-option v-for="item in econTypeList" :key="item.value" :label="item.label"
									:value="item.value" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="国民经济行业分类">
							<el-select v-model="ruleForm.v_EconCategory" placeholder="国民经济行业分类" clearable
								style="width: 100%">
								<el-option v-for="item in econCategoryList" :key="item.value" :label="item.label"
									:value="item.value" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="v_RegulatoryIndustry" label="监管行业">
							<el-input v-model="ruleForm.v_RegulatoryIndustry" placeholder="监管行业" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="法人代表人（经营者）">
							<el-input v-model="ruleForm.v_LegalRepresentative" placeholder="法人代表人（经营者）" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="联系电话">
							<el-input v-model.number="ruleForm.v_ContactNumber" placeholder="联系电话" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="v_RegisAddrCode" label="注册地址行政区划">
							<el-input v-model="ruleForm.v_RegisAddrCode" placeholder="注册地址行政区划" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="v_RegisAddr" label="注册地址">
							<el-input v-model="ruleForm.v_RegisAddr" placeholder="注册地址" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="v_AddressOperatingCode" label="经营地址行政区划">
							<el-input v-model="ruleForm.v_AddressOperatingCode" placeholder="经营地址行政区划" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="v_AddressOperating" label="经营地址">
							<el-input v-model="ruleForm.v_AddressOperating" placeholder="经营地址" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="f_LocationCoordinatesLongitude" label="所在地坐标-经度">
							<el-input v-model="ruleForm.f_LocationCoordinatesLongitude" placeholder="所在地坐标-经度"
								clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="f_LocationCoordinatesLatitude" label="所在地坐标-纬度">
							<el-input v-model="ruleForm.f_LocationCoordinatesLatitude" placeholder="所在地坐标-纬度"
								clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="企业是否位于化工园区">
							<el-radio-group v-model="ruleForm.isLocatedChemical" style="width: 100%">
								<el-radio :value="true" :label="true">是</el-radio>
								<el-radio :value="false" :label="false">否</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="企业规模">
							<el-select v-model="ruleForm.v_EntpSize" placeholder="企业规模" clearable style="width: 100%">
								<el-option v-for="item in entpSizeList" :key="item.value" :label="item.label"
									:value="item.value" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="成立日期">
							<el-date-picker v-model="ruleForm.degisterDate" type="date" format="YYYY/MM/DD"
								style="width: 100%" value-format="YYYY/MM/DD" placeholder="成立日期" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="注册资本（万元）">
							<el-input v-model.number="ruleForm.n_RegCap" placeholder="注册资本（万元）" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="主营业务">
							<el-input v-model="ruleForm.v_OpScope" placeholder="主营业务" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="l_MainInChargeId" label="主要负责人">
							<el-select v-model="ruleForm.l_MainInChargeId" placeholder="主要负责人" clearable
								style="width: 100%">
								<el-option v-for="item in mainInChargeList" :key="item.value" :label="item.label"
									:value="item.value" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="l_SafetyProductionManagementId" label="全生产管理负责人">
							<el-select v-model="ruleForm.l_SafetyProductionManagementId" placeholder="全生产管理负责人"
								clearable style="width: 100%">
								<el-option v-for="item in mainInChargeList" :key="item.value" :label="item.label"
									:value="item.value" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="l_SafeOrgId" label="安全生产管理机构">
							<el-select v-model="ruleForm.l_SafeOrgId" placeholder="安全生产管理机构" clearable
								style="width: 100%">
								<el-option v-for="item in safeOrgList" :key="item.value" :label="item.label"
									:value="item.value" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item prop="d_SafeOrgEstablishDate" label="安全生产管理机构设（调整）日期">
							<el-date-picker v-model="ruleForm.d_SafeOrgEstablishDate" type="date" format="YYYY/MM/DD"
								style="width: 100%" value-format="YYYY/MM/DD" placeholder="安全生产管理机构设（调整）日期" />
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancelUseClick">取消</el-button>
					<el-button type="primary" @click="controlUseClick(formRef)">确定</el-button>
				</span>
			</template>
		</el-dialog>
		<!-- 详情 -->
		<el-dialog draggable :close-on-click-modal="false" :close-on-press-escape="false"
			v-model="showDialogVisibleInfo" title="详情" width="50%" @close="showDialogVisibleInfo = false">
			<el-descriptions title="" border :column="2">
				<el-descriptions-item>
					<template #label> 记录Id </template> {{ qualificationDetail.id }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 企业名称 </template> {{ qualificationDetail.v_Name }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 统一社会信用代码 </template> {{ qualificationDetail.v_Uniscid }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 营业状态名称 </template> {{ qualificationDetail.v_BusinessStatusName }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 组织机构代码 </template> {{ qualificationDetail.v_OrganizationCode }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 所属行政区域编码 </template> {{ qualificationDetail.v_AdminsrtativeDivision }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 国民经济类型名称 </template> {{ qualificationDetail.v_EconTypeName }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 国民经济行业分类 </template> {{ econCategoryList.find(item => item.value ==
						qualificationDetail.v_EconCategory).label }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 监管行业 </template> {{ qualificationDetail.v_RegulatoryIndustry }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 法人代表人（经营者） </template> {{ qualificationDetail.v_LegalRepresentative }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 联系电话 </template> {{ qualificationDetail.v_ContactNumber }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 注册地址行政区划 </template> {{ qualificationDetail.v_RegisAddrCode }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 注册地址 </template> {{ qualificationDetail.v_RegisAddr }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 经营地址行政区划 </template> {{ qualificationDetail.v_AddressOperatingCode }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 经营地址 </template> {{ qualificationDetail.v_AddressOperating }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 所在地坐标-经度 </template> {{ qualificationDetail.f_LocationCoordinatesLongitude }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 所在地坐标-纬度 </template> {{ qualificationDetail.f_LocationCoordinatesLatitude }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 企业是否位于化工园区 </template> {{ qualificationDetail.isLocatedChemical ? '是' : '否' }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 化工园区名称 </template> {{ qualificationDetail.v_ChemicalIndustryPark }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 企业规模 </template>{{ entpSizeList.find(item => item.value ==
						qualificationDetail.v_EntpSize).label }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 成立日期 </template> {{ qualificationDetail.degisterDate }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 注册资本（万元） </template> {{ qualificationDetail.n_RegCap }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 主营业务 </template> {{ qualificationDetail.l_MainInChargeId }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 主要负责人名称 </template> {{ qualificationDetail.v_MainInChargeName }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 安全生产管理负责人名称 </template> {{ qualificationDetail.v_SafetyProductionManagementName }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 安全生产管理机构名称 </template> {{ qualificationDetail.v_SafeOrgName }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label>安全生产管理机构设日期 </template> {{ qualificationDetail.d_SafeOrgEstablishDate }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label>安全生产管理机构设设立文件id </template> {{ qualificationDetail.f_SafeOrgEstablishFiles }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 备注 </template> {{ qualificationDetail.v_Remark }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 最后一次数据同步时间 </template> {{ qualificationDetail.d_LastDSTime }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 发起同步时间 </template> {{ qualificationDetail.d_InitiateDSTime }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 待同步至双控 </template> {{ qualificationDetail.isTobeDS ? '是' : '否' }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 创建时间 </template> {{ qualificationDetail.createdTime }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 创建人 </template> {{ qualificationDetail.createdUserName }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 更新时间 </template> {{ qualificationDetail.updatedTime }}
				</el-descriptions-item>
				<el-descriptions-item>
					<template #label> 更新人 </template> {{ qualificationDetail.updatedUserName }}
				</el-descriptions-item>
			</el-descriptions>
		</el-dialog>
		<!-- 文件 -->
		<uploadFile isAccept="" :fileInfo="fileInfo" :isUseDialog="fileDialog" @cancelFileClick="cancelFileClick"
			@controlFileClick="controlFileClick" />
	</div>
</template>
<script lang="ts" setup>
import { ref, reactive, onMounted } from 'vue';
import { FormInstance } from 'element-plus';
import { createBiochemistryMolecularBiologyApi, getBiochemistryMolecularBiologyApi, getSnowflakeIdApi, sysDictDataList, SysEmpSelector, sysOrgList, updateBiochemistryMolecularBiologyApi } from '/@/api/centerControl/oms';
import uploadFile from '/@/views/oms/component/reviseUploadFile.vue'

//#region 新增/编辑/表单校验
//经营状态
const businessStatuLis = [
	{ label: '营业', value: 1 },
	{ label: '停业', value: 2 },
	{ label: '关闭', value: 3 },
];
//国民经济类型
const econTypeList = [
	{ label: '国有企业', value: 1 },
	{ label: '集体企业', value: 2 },
	{ label: '私营企业', value: 3 },
	{ label: '其他企业', value: 5 },
	{ label: '股份合作企业', value: 6 },
	{ label: '联营企业', value: 7 },
	{ label: '有限责任公司', value: 8 },
	{ label: '股份有限公司', value: 9 },
	{ label: '港、澳、台商投资企业', value: 11 },
	{ label: '分公司', value: 12 },
	{ label: '外商投资企业', value: 13 },
];
//安全生产机构-组织部门
const safeOrgList: any = ref([])
//员工/负责人
const mainInChargeList: any = ref([])
//国民经济行业分类 新增字典
const econCategoryList: any = ref([])
//企业规模 字典
const entpSizeList: any = ref([])
//表单数据
const ruleForm: any = reactive({
	v_Name: '',//企业名称  *
	v_Uniscid: '',//统一社会信用代码  *
	n_BusinessStatus: '',//营业状态  businessStatuLis  *
	v_OrganizationCode: '',//组织机构代码
	v_AdminsrtativeDivision: '',//所属行政区域编码  *
	n_EconType: '',//国民经济类型  econTypeList
	v_EconCategory: '',//国民经济行业分类   字典
	v_RegulatoryIndustry: '',//监管行业  *
	v_LegalRepresentative: '',//法人代表人（经营者）
	v_ContactNumber: '',//联系电话
	v_RegisAddrCode: '',//注册地址行政区划
	v_RegisAddr: '',//注册地址  *
	v_AddressOperatingCode: '',//经营地址行政区划  *
	v_AddressOperating: '',//经营地址  *
	f_LocationCoordinatesLongitude: '',//所在地坐标-经度 精度15,8  *
	f_LocationCoordinatesLatitude: '',//所在地坐标-纬度 精度15,8  *
	isLocatedChemical: true,//企业是否位于化工园区
	v_ChemicalIndustryPark: '',//化工园区名称
	v_EntpSize: '',//企业规模(取数据字典) 字典
	degisterDate: '',//成立日期（日期格式：yyyy-MM-dd ）
	n_RegCap: '',//注册资本（万元）
	v_OpScope: '',//主营业务
	l_MainInChargeId: '',//主要负责人(员工)id  *
	l_SafetyProductionManagementId: '',//安全生产管理负责人(员工)id  *
	l_SafeOrgId: '',//安全生产管理机构id  *
	d_SafeOrgEstablishDate: '',//安全生产管理机构设（调整）日期（时间格式：yyyy-MM-dd）  *
	f_SafeOrgEstablishFiles: 0,//安全生产管理机构设 设立（调整）文件id  *
});
// 表单校验
const rules = reactive({
	v_Name: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	v_Uniscid: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	n_BusinessStatus: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	v_AdminsrtativeDivision: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	v_RegulatoryIndustry: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	v_RegisAddrCode: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	v_RegisAddr: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	v_AddressOperatingCode: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	v_AddressOperating: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	f_LocationCoordinatesLongitude: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	f_LocationCoordinatesLatitude: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	l_MainInChargeId: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	l_SafetyProductionManagementId: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	l_SafeOrgId: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	d_SafeOrgEstablishDate: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
	//f_SafeOrgEstablishFiles: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
});

// 新增/编辑
const showDialogVisible = ref(false);
const editId = ref(0);
const nodeClick = async (obj: any) => {
	console.log(obj, "enterpriseInformation");
	if (obj.id) {
		editId.value = obj.id;
		ruleForm.v_Name = obj.v_Name;//企业名称  *
		ruleForm.v_Uniscid = obj.v_Uniscid;//统一社会信用代码  *
		ruleForm.n_BusinessStatus = obj.n_BusinessStatus;//营业状态  businessStatuLis  *
		ruleForm.v_OrganizationCode = obj.v_OrganizationCode;//组织机构代码
		ruleForm.v_AdminsrtativeDivision = obj.v_AdminsrtativeDivision;//所属行政区域编码  *
		ruleForm.n_EconType = obj.n_EconType;//国民经济类型  econTypeList
		ruleForm.v_EconCategory = obj.v_EconCategory;//国民经济行业分类   字典
		ruleForm.v_RegulatoryIndustry = obj.v_RegulatoryIndustry;//监管行业  *
		ruleForm.v_LegalRepresentative = obj.v_LegalRepresentative;//法人代表人（经营者）
		ruleForm.v_ContactNumber = obj.v_ContactNumber;//联系电话
		ruleForm.v_RegisAddrCode = obj.v_RegisAddrCode;//注册地址行政区划
		ruleForm.v_RegisAddr = obj.v_RegisAddr;//注册地址  *
		ruleForm.v_AddressOperatingCode = obj.v_AddressOperatingCode;//经营地址行政区划  *
		ruleForm.v_AddressOperating = obj.v_AddressOperating;//经营地址  *
		ruleForm.f_LocationCoordinatesLongitude = obj.f_LocationCoordinatesLongitude;//所在地坐标-经度 精度15;8  *
		ruleForm.f_LocationCoordinatesLatitude = obj.f_LocationCoordinatesLatitude;//所在地坐标-纬度 精度15;8  *
		ruleForm.isLocatedChemical = obj.isLocatedChemical;//企业是否位于化工园区
		ruleForm.v_ChemicalIndustryPark = obj.v_ChemicalIndustryPark;//化工园区名称
		ruleForm.v_EntpSize = Number( obj.v_EntpSize);//企业规模(取数据字典) 字典
		ruleForm.degisterDate = obj.degisterDate;//成立日期（日期格式：yyyy-MM-dd ）
		ruleForm.n_RegCap = obj.n_RegCap;//注册资本（万元）
		ruleForm.v_OpScope = obj.v_OpScope;//主营业务
		ruleForm.l_MainInChargeId = obj.l_MainInChargeId;//主要负责人(员工)id  *
		ruleForm.l_SafetyProductionManagementId = obj.l_SafetyProductionManagementId;//安全生产管理负责人(员工)id  *
		ruleForm.l_SafeOrgId = String(obj.l_SafeOrgId);//安全生产管理机构id  *
		ruleForm.d_SafeOrgEstablishDate = obj.d_SafeOrgEstablishDate;//安全生产管理机构设（调整）日期（时间格式：yyyy-MM-dd）  *
		ruleForm.f_SafeOrgEstablishFiles = obj.f_SafeOrgEstablishFiles;//安全生产管理机构设 设立（调整）文件id  *
	} else {
		const res = await getSnowflakeIdApi()
		ruleForm.f_SafeOrgEstablishFiles = res.data
	}
	showDialogVisible.value = true;
};


//弹窗取消
const cancelUseClick = () => {
	showDialogVisible.value = false;
	formRef.value?.resetFields();
	editId.value = 0;
	ruleForm.v_Name = '';//企业名称  *
	ruleForm.v_Uniscid = '';//统一社会信用代码  *
	ruleForm.n_BusinessStatus = '';//营业状态  businessStatuLis  *
	ruleForm.v_OrganizationCode = '';//组织机构代码
	ruleForm.v_AdminsrtativeDivision = '';//所属行政区域编码  *
	ruleForm.n_EconType = '';//国民经济类型  econTypeList
	ruleForm.v_EconCategory = '';//国民经济行业分类   字典
	ruleForm.v_RegulatoryIndustry = '';//监管行业  *
	ruleForm.v_LegalRepresentative = '';//法人代表人（经营者）
	ruleForm.v_ContactNumber = '';//联系电话
	ruleForm.v_RegisAddrCode = '';//注册地址行政区划
	ruleForm.v_RegisAddr = '';//注册地址  *
	ruleForm.v_AddressOperatingCode = '';//经营地址行政区划  *
	ruleForm.v_AddressOperating = '';//经营地址  *
	ruleForm.f_LocationCoordinatesLongitude = '';//所在地坐标-经度 精度15;8  *
	ruleForm.f_LocationCoordinatesLatitude = '';//所在地坐标-纬度 精度15;8  *
	ruleForm.isLocatedChemical = true;//企业是否位于化工园区
	ruleForm.v_ChemicalIndustryPark = '';//化工园区名称
	ruleForm.v_EntpSize = '';//企业规模(取数据字典) 字典
	ruleForm.degisterDate = '';//成立日期（日期格式：yyyy-MM-dd ）
	ruleForm.n_RegCap = '';//注册资本（万元）
	ruleForm.v_OpScope = '';//主营业务
	ruleForm.l_MainInChargeId = '';//主要负责人(员工)id  *
	ruleForm.l_SafetyProductionManagementId = '';//安全生产管理负责人(员工)id  *
	ruleForm.l_SafeOrgId = '';//安全生产管理机构id  *
	ruleForm.d_SafeOrgEstablishDate = '';//安全生产管理机构设（调整）日期（时间格式：yyyy-MM-dd）  *
	//ruleForm.f_SafeOrgEstablishFiles = '';//安全生产管理机构设 设立（调整）文件id  *
	ruleForm.f_SafeOrgEstablishFiles = 0
};

//表单提交事件
const formRef = ref<FormInstance>();
const controlUseClick = async (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	await formEl.validate((valid, fields) => {
		if (valid) {
			console.log('submit!');
			if (editId.value) {
				updateBiochemistryMolecularBiologyApi({ ...ruleForm, id: editId.value }).then(() => {
					cancelUseClick();
					getProductUnitList()
				});
			} else {
				createBiochemistryMolecularBiologyApi(ruleForm).then(() => {
					cancelUseClick();
					getProductUnitList()
				});
			}
		} else {
			console.log('error submit!', fields);
		}
	});
};
//#endregion

//#region  详情
const showDialogVisibleInfo = ref(false);
const qualificationDetail = ref()
const editIdInfoHandler = (row) => {
	qualificationDetail.value = row
	showDialogVisibleInfo.value = true
};
//#endregion

//#region  附件上传下载
const fileInfo = ref();
const fileDialog = ref(false);
/*** cancelFileClick 文件上传取消事件 */
const cancelFileClick = (val: boolean) => {
	fileDialog.value = val;
};

/*** controlFileClick 文件上传提交事件 */
const controlFileClick = () => {
	fileDialog.value = false;
};

/*** documentClick 文档下载事件 */
const documentClick = async (val: any) => {
	val.sourceId = val.f_SafeOrgEstablishFiles
	val.sourceType = 11
	fileInfo.value = JSON.stringify(val);
	fileDialog.value = true;
};
//#endregion


//获取列表
const productUnitList = ref([]);
const getProductUnitList = async () => {
	const res = await getBiochemistryMolecularBiologyApi({})
	productUnitList.value = res.data
}
onMounted(async () => {
	getProductUnitList();
	//获取国民经济行业分类
	const res3 = await sysDictDataList({ TypeCode: 'oms_classificationIndustry' });
	econCategoryList.value = res3.data.map((element: any) => {
		return {
			label: element.value,
			value: element.id,
		}
	});
	//企业规模
	const res4 = await sysDictDataList({ TypeCode: 'oms_enterprise' });
	entpSizeList.value = res4.data.map((element: any) => {
		return {
			label: element.value,
			value: element.id,
		}
	});
	// 获取员工
	const res1 = await SysEmpSelector();
	mainInChargeList.value = res1.data.map((item: any) => {
		return {
			label: item.name,
			value: item.id,
		};
	})
	//获取组织机构
	const res2 = await sysOrgList()
	safeOrgList.value = res2.data.map((item: any) => {
		return {
			label: item.name,
			value: item.id,
		}
	})

});

</script>
<style lang="scss">
@import '../style/public.scss';
</style>
<style scoped lang="scss">
#friend-merchant-manage {
	.box-f {
		:deep(.el-form-item__label) {
			padding: 0;
		}
	}

	:deep(.el-card__body) {
		height: 100%;
	}

	:deep(.el-card) {
		border: none !important;
	}

	.upload-demo {
		margin-left: 12px;
		margin-top: 2px;
	}

	ul {
		list-style: none;

		li {
			cursor: pointer;

			&:hover {
				color: red;
			}
		}
	}

	.icon-e {
		:deep(.el-icon) {
			margin-right: 0px !important;
		}
	}

	.upload-s {
		:deep(.el-upload--picture-card) {
			background-color: rgba(255, 255, 255, 0) !important;
		}
	}
}
</style>
